<?php

namespace app\admin\model;

use think\Model;


class Article extends Model
{

    

    

    // 表名
    protected $name = 'article';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'createtime_text',
        'updatetime_text',
    ];
    public function getCreatetimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['createtime']);
    }
    public function getUpdatetimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['updatetime']);
    }

    







    public function category()
    {
        return $this->belongsTo('Category', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function setCreatetimeAttr($value,$data){
        return isset($data['createtime'])?(is_numeric($data['createtime'])?$data['createtime']:strtotime($value)):time();
    }
}
